<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateTableStudent extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table  =  $this->table('student',array('engine'=>'InnoDB'));
        $table->addColumn('account','char',array('limit' => 11,'comment'=>'登录账号'))
                ->addColumn('password','string',array('limit' => 255,'comment'=>'密码'))
                ->addColumn('truename','string',array('limit' => 20,'comment'=>'真实姓名'))
                ->addColumn('amount','decimal',array('default' => 0.00,'precision'=>5,'scale'=>2,'comment'=>'账户余额'))
                ->addColumn('course_id','integer',array('limit' => 30,'comment'=>'课程ID'))
                ->addColumn('semester_id','integer',array('limit' => 30,'comment'=>'学期ID'))
                ->addColumn('province_code','integer',array('comment'=>'省编码'))
                ->addColumn('city_code','integer',array('comment'=>'市编码'))
                ->addColumn('progress','boolean',array('default' => 0,'comment'=>'进度'))
                ->addColumn('avatar','string',array('limit' => 100,'default'=>'','comment'=>'用户头像'))
                ->addColumn('gender','boolean',array('limit' => 4,'default'=>1,'comment'=>'1:男,0:女'))
                ->addColumn('birthday','date',array('comment'=>'生日','null'=>false))
                ->addColumn('open_id','string',array('limit' => 200,'default'=>'','comment'=>'微信id'))
                ->addColumn('last_login_time','datetime',array('comment'=>'最后登录时间','null'=>true))
                ->addColumn('last_login_ip', 'integer',array('limit'  =>  11,'default'=>0,'comment'=>'最后登录IP'))
                ->addColumn('status','boolean',array('limit' => 4,'default'=>1,'comment'=>'1:启用,0:禁用'))
                ->addColumn('referrer','string',array('limit' => 50,'comment'=>'推荐人姓名'))
                ->addColumn('source_id','integer',array('limit' => 4,'comment'=>'来源Id'))
                ->addColumn('apply_time','date',array('comment'=>'报名时间'))
                ->addColumn('create_time','datetime',array('comment'=>'创建时间'))
                ->addColumn('update_time','datetime',array('comment'=>'修改时间'))
                ->addColumn('delete_time','datetime',array('comment'=>'删除时间','null'=>true))
                ->addIndex(array('account'), array('unique'  =>  true))
                ->create();
    }
}
